﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;

namespace 管理信息查询
{
    public partial class 管理信息查询主窗体 : Form
    {
        public 管理信息查询主窗体()
        {
            InitializeComponent();
        }

        public void ObjQuery(string selectSql, string concont)
        {
            SelectQuery q = new SelectQuery(selectSql, concont);
            ManagementObjectSearcher s = new ManagementObjectSearcher(q);

            listBox1.Items.Clear();
            foreach (ManagementObject service in s.Get())
            {
                listBox1.Items.Add(service.ToString());
            }
        }

        public void ObjQuery(string selectSql)
        {
            SelectQuery q = new SelectQuery(selectSql);
            ManagementObjectSearcher s = new ManagementObjectSearcher(q);

            listBox1.Items.Clear();
            foreach (ManagementObject service in s.Get())
            {
                //listBox1.Items.Add(service.Properties["Size"].ToString());
                listBox1.Items.Add(service.ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ObjQuery("Win32_Service", "State='Running'");
            ObjQuery("select * from meta_class");                              // WMI 类别
            ObjQuery("select * from Win32_Processor");                         // CPU 处理器
            ObjQuery("select * from Win32_PhysicalMemory");                    // 物理内存
            ObjQuery("select * from Win32_Keyboard");                         // 键盘
            ObjQuery("select * from Win32_PointingDevice");                    // 点输入设备，如鼠标
            ObjQuery("select * from Win32_DiskDrive");                    // 硬盘驱动器
            ObjQuery("select * from Win32_CDROMDrive");                    // 光盘驱动器
            ObjQuery("select * from Win32_BaseBoard");                    // 主板
            ObjQuery("select * from Win32_BIOS");                    // BIOS 芯片
            ObjQuery("select * from Win32_ParallelPort");                    // 并口
            ObjQuery("select * from Win32_SerialPort");                    // 串口
            ObjQuery("select * from Win32_SoundDevice");                    // 多媒体设置
            ObjQuery("select * from Win32_USBController");                    // USB 控制器
            ObjQuery("select * from Win32_NetworkAdapter");                    // 网络适配器
            ObjQuery("select * from Win32_NetworkAdapterConfiguration");                    // 网络适配器设置
            ObjQuery("select * from Win32_Printer");                    // 打印机
            ObjQuery("select * from Win32_PrinterConfiguration");                    // 打印机设置
            ObjQuery("select * from Win32_PrintJob ");                    // 打印机任务
            ObjQuery("select * from Win32_TCPIPPrinterPort");                    // 打印机端口
            ObjQuery("select * from Win32_POTSModem");                    // MODEM 
            ObjQuery("select * from Win32_POTSModemToSerialPort   ");                    // MODEM 端口
            ObjQuery("select * from Win32_DesktopMonitor");                    // 显示器
            ObjQuery("select * from Win32_VideoController");                    // 显卡细节。
            ObjQuery("select * from Win32_VideoSettings");                    // 显卡支持的显示模式。
            ObjQuery("select * from Win32_TimeZone ");                    // 时区
            ObjQuery("select * from Win32_SystemDriver");                    // 驱动程序
            ObjQuery("select * from Win32_DiskPartition           ");                    // 磁盘分区
            ObjQuery("select * from Win32_LogicalDisk");                    // 逻辑磁盘
            ObjQuery("select * from Win32_LogicalMemoryConfiguration   ");                    // 逻辑内存配置
            ObjQuery("select * from Win32_PageFile ");                    // 系统页文件信息
            ObjQuery("select * from Win32_PageFileSetting         ");                    // 页文件设置
            ObjQuery("select * from Win32_BootConfiguration       ");                    // 系统启动配置
            ObjQuery("select * from Win32_OperatingSystem         ");                    // 操作系统信息
            ObjQuery("select * from Win32_StartupCommand          ");                    // 系统自动启动程序
            ObjQuery("select * from Win32_Service  ");                    // 系统安装的服务
            ObjQuery("select * from Win32_Group    ");                    // 系统管理组
            ObjQuery("select * from Win32_GroupUser");                    // 系统组帐号
            //ObjQuery("select * from Win32_UserAccount");                    // 用户帐号
            //ObjQuery("select * from Win32_Process  ");                    // 系统进程
            //ObjQuery("select * from Win32_Thread   ");                    // 系统线程
            //ObjQuery("select * from Win32_Share    ");                    // 共享
            //ObjQuery("select * from Win32_NetworkClient           ");                    // 已安装的网络客户端
            //ObjQuery("select * from Win32_NetworkProtocol         ");                    // 已安装的网络协议
        }


        protected void BtnReStart_Click(object sender, EventArgs e)
        {
            //计算机操作辅助类,下面有完整源码 
            ComputerOperator co = new ComputerOperator("metarnet", "741258", "192.168.6.129");
            bool result = false;
            if (this.OperaType.Text == "0")
            {
                result = co.ExecutuOperator(OperatorType.Close);//关闭 
            }
            else if (this.OperaType.Text == "1")
            {
                result = co.ExecutuOperator(OperatorType.ReStart);//重启 
            }
            else
            {
                result = co.ExecutuOperator(OperatorType.ResetUser);//注销 
            }

            if (result == true)
            {
                MessageBox.Show("执行成功");
            }
            else
            {
                MessageBox.Show("执行失败");
                //Response.Write("执行失败");
            }
            co = null;
        }
    }





}